package co.gov.medellin.ssti.sub.service;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;

import org.junit.Test;

import oracle.jdbc.pool.OracleConnectionPoolDataSource;

import junit.framework.TestCase;
import co.gov.medellin.ssti.sub.common.dao.TransactionUtil;
import co.gov.medellin.ssti.sub.common.excepcion.SUBException;
import co.gov.medellin.ssti.sub.model.vo.BeneficiarioVO;

public class BeneficioServiceTesst extends TestCase {
	InitialContext ic;
	OracleConnectionPoolDataSource ds;
	private BeneficioService beneficioService = new BeneficioService();
	private BeneficiarioService beneficiarioService = new BeneficiarioService();

	protected void setUp() throws Exception {
		// rcarver - setup the jndi context and the datasource
		try {
			// Create initial context
			System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
					"org.apache.naming.java.javaURLContextFactory");
			System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
			ic = new InitialContext();
			ic.createSubcontext("java:");
			ic.createSubcontext("java:/comp");
			ic.createSubcontext("java:/comp/env");
			ic.createSubcontext("java:/comp/env/jdbc");

			// Construct DataSource
			ds = new OracleConnectionPoolDataSource();
			ds.setURL("jdbc:oracle:thin:@localhost:1521:xe");
			ds.setUser("BENEFICIOS");
			ds.setPassword("beneficios");
			ic.bind("java:/comp/env/jdbc/ds_beneficios", ds);
		} catch (NamingException ex) {
			// fail(ex.toString());
			/*
			 * Logger.getLogger(AtributosDAOImpl.class.getName()).log(
			 * Level.SEVERE, null, ex);
			 */
		} finally {

		}
	}

	protected void tearDown() throws Exception {
		if (ic != null) {
			ic.close();
		}
	}

	@Test
	public void testIsExisteBeneficiario() {
		UserTransaction utx = null;
		utx = TransactionUtil.getUserTransaction();
		try {
			// Inicio transaction.
			utx.begin();
			BeneficiarioVO beneficiarioVO = new BeneficiarioVO();
			beneficiarioVO.setNumeroDocumento("71389788");
			beneficiarioVO.setTipoDocumento("C");
			beneficiarioVO.setNombre1("FEDERICO");
			beneficiarioVO.setNombre2(null);
			beneficiarioVO.setPrimerApellido("SIERRA");
			beneficiarioVO.setSegundoApellido("ROBLEDO");
			beneficiarioVO.setVflComuna(null);
			beneficiarioVO.setFechaNacimiento("01/01/1900");
			beneficiarioVO.setSexo("M");
			beneficiarioVO.setTelefono("4220499");
			beneficiarioVO.setDirDescriptiva("cll 79C #75-37");
			beneficiarioVO.setDirEncasillada(null);
			beneficiarioVO.setCobama(null);
			beneficiarioVO.setCodeBarrio(null);
			beneficiarioVO.setCodeZona(null);
			beneficiarioVO.setMail("fedsierra@gmail.com");
			beneficiarioVO.setEtnia("O");
			beneficiarioVO.setCreationUser("BENEFICIOS");
			beneficiarioVO.setCreationTerminal("UNKWNOWN");
			beneficiarioVO.setCreationDate("01/01/2013");
			beneficiarioVO.setUpdateUser(null);
			beneficiarioVO.setUpdateTerminal(null);
			beneficiarioVO.setUpdateDate(null);

			String codeBeneficiario = "";

			String[] resp = beneficiarioService.insert(beneficiarioVO);
			if (resp[0].equalsIgnoreCase("true")) {
				codeBeneficiario = resp[1];
			} else {
				fail("FUCK");
			}

			// Fin - Commit transaction.
			utx.rollback();
			fail("ok");
		} catch (Exception e) {
			if (utx != null) {
				try {
					// Rollback si hay error.
					utx.rollback();
				} catch (SystemException sysex) {
					SUBException.logDebugError(
							"otorgarBeneficios.otorgarBeneficios: ", sysex);
				}
			}
		}
	}

	public void testFindCostoBeneficio() {
		fail("Not yet implemented");
	}

	public void testFindCostoBOT() {
		fail("Not yet implemented");
	}

	public void testFindFechaBOT() {
		fail("Not yet implemented");
	}

	public void testFindTercero() {
		fail("Not yet implemented");
	}

	public void testFindTipoBeneficio() {
		fail("Not yet implemented");
	}

	public void testFindDisponibilidad() {
		fail("Not yet implemented");
	}

	public void testOtorgarBeneficiosLongLongLongListOfBeneficiario_AtributoVOStringIntStringArrayStringString() {
		fail("Not yet implemented");
	}

	public void testOtorgarBeneficiosLongLongLongListOfBeneficiario_AtributoVOStringIntStringArrayStringStringString() {
		fail("Not yet implemented");
	}

	public void testUpdateBOT() {
		fail("Not yet implemented");
	}

	public void testFindSedeBOT() {
		fail("Not yet implemented");
	}

	public void testFindDetallesBeneficios() {
		fail("Not yet implemented");
	}

	public void testDeleteBOT() {
		fail("Not yet implemented");
	}

	public void testValidarDeleteBOT() {
		fail("Not yet implemented");
	}

	public void testValidarEditBOT() {
		fail("Not yet implemented");
	}

	public void testRenewBeneficio() {
		fail("Not yet implemented");
	}

	public void testFindUsuarioxBeneficio() {
		fail("Not yet implemented");
	}

	public void testFindPrograma() {
		fail("Not yet implemented");
	}

}
